/**
 * QueryMappTestDataSVImpl.java	  V1.0   Feb 20, 2012 3:40:30 PM
 *
 * Copyright 2011 AsiaInfo Linkage, All rights reserved.
 *
 * Modification history(By    Time    Reason):
 * 
 * Description:
 */

package psn.service.person.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.ai.utils.DBUtil;

import psn.bean.person.MappTestDataBean;
import psn.bean.person.MappTestDataEngine;
import psn.service.person.interfaces.IQueryMappTestDataSV;
import psn.usermodel.PersonSearchModel;
import xframe.core.flexigrid.FlexiGridResult;
import xframe.core.flexigrid.FlexiGridUtils;


/**
 * 功能描述：
 *
 * @author  余根宁
 *
 * <p>修改历史：(修改人，修改时间，修改原因/内容)</p>
 */
public class QueryMappTestDataSVImpl implements IQueryMappTestDataSV {
    
    /* (non-Javadoc)
     * @see psn.service.person.interfaces.IQueryMappTestDataSV#queryDataBySearchModel(psn.usermodel.PersonSearchModel)
     */
    public String queryDataBySearchModel(PersonSearchModel searchModel) throws Exception {
        Map parameters = new HashMap();
        parameters.clear();
        String sql = "1=1";
        
        if(StringUtils.isNotEmpty(searchModel.getAreaCode())){
            sql +=" and area_code = :code";
            parameters.put("code", searchModel.getAreaCode());
        }
        
        if(!StringUtils.isEmpty(searchModel.getSortname())){
            sql += " order by " + searchModel.getSortname() + " " + searchModel.getSortorder();
        }
        int cnt = MappTestDataEngine.getBeansCount(sql, parameters);
        MappTestDataBean[] beans = MappTestDataEngine.getBeans(null, sql, parameters, searchModel.buildPageFirst(), searchModel.buildPageLast(), false);
        //MappTestDataBean[] beans = createDemoBeans();
        
        return FlexiGridUtils.generateFlexiGridJson(cnt, searchModel.getPage(), beans);
    }
    
    /*private MappTestDataBean[] createDemoBeans() throws Exception {
        MappTestDataBean[] beans = new MappTestDataBean[5];
        beans[0] = new MappTestDataBean();
        beans[0].setAreaCode("380");
        beans[0].setCol1(130);
        beans[0].setCol2(230);
        
        beans[1] = new MappTestDataBean();
        beans[1].setAreaCode("381");
        beans[1].setCol1(130);
        beans[1].setCol2(230);
        
        beans[2] = new MappTestDataBean();
        beans[2].setAreaCode("382");
        beans[2].setCol1(130);
        beans[2].setCol2(230);
        
        beans[3] = new MappTestDataBean();
        beans[3].setAreaCode("383");
        beans[3].setCol1(130);
        beans[3].setCol2(230);
        
        beans[4] = new MappTestDataBean();
        beans[4].setAreaCode("384");
        beans[4].setCol1(130);
        beans[4].setCol2(230);
        
        
        return null;
    }*/
    
}
